package wc.fileUtil;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import wc.fileUtil.exception.NoReadableFileException;

public class ComputeraFileReader extends FileReader {

	public ComputeraFileReader(String encode) {
		super(encode);
	}

	@Override
	public void parseFile(File file) throws NoReadableFileException {
		clear();
		if(file.isDirectory()) throw new NoReadableFileException();
		Pattern p = Pattern.compile("^\\=+$");
        Matcher m;
        int countMatcher = 0;
        String s;
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), getEncode()));
            while((s = br.readLine()) != null) {
                m = p.matcher(s);
                if(m.find()) {
                    countMatcher++;
                    continue;
                }
                if(countMatcher == 2) {
                    addLine(s);
                } else if(countMatcher == 3) {
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
}
